/*
 * KanghuixingView.java
 */

package kanghuixing;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.StreamTokenizer;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

/**
 * The application's main frame.
 */
public class KanghuixingView extends FrameView {
    
    static protected int num,len;
    protected int theSign = 0;//为0表示小图显示，为1表示大图显示……
    static protected int[][] point;
    static protected int[][] map1;
    protected Color pointColor[];
    static protected int choiceP[],choiceE[][];
    protected boolean Import = false;
    protected int ImportNum[],ImportN;
    private JFileChooser fileChooser;
    
    
    public KanghuixingView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = KanghuixingApp.getApplication().getMainFrame();
            aboutBox = new KanghuixingAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        KanghuixingApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel2 = new javax.swing.JPanel();
        jSplitPane2 = new javax.swing.JSplitPane();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setName("mainPanel"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(kanghuixing.KanghuixingApp.class).getContext().getActionMap(KanghuixingView.class, this);
        jButton1.setAction(actionMap.get("jButton1_Click")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(kanghuixing.KanghuixingApp.class).getContext().getResourceMap(KanghuixingView.class);
        jButton1.setLabel(resourceMap.getString("jButton1.label")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addContainerGap(990, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1))
        );

        jSplitPane1.setName("jSplitPane1"); // NOI18N

        jPanel2.setBackground(resourceMap.getColor("jPanel2.background")); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 109, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 620, Short.MAX_VALUE)
        );

        jSplitPane1.setLeftComponent(jPanel2);

        jSplitPane2.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPane2.setName("jSplitPane2"); // NOI18N

        jPanel3.setBackground(resourceMap.getColor("jPanel3.background")); // NOI18N
        jPanel3.setName("jPanel3"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 953, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        jSplitPane2.setTopComponent(jPanel3);

        jPanel4.setBackground(resourceMap.getColor("jPanel4.background")); // NOI18N
        jPanel4.setName("jPanel4"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 953, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 513, Short.MAX_VALUE)
        );

        jSplitPane2.setRightComponent(jPanel4);

        jSplitPane1.setRightComponent(jSplitPane2);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1071, Short.MAX_VALUE)
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 622, Short.MAX_VALUE))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        jMenuItem1.setAction(actionMap.get("open_File")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        fileMenu.add(jMenuItem1);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 1081, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 911, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void jButton1_Click() {
        Import = false;
        num=newtestmap();
        Graphics2D  g=(Graphics2D)jPanel2.getGraphics();
        drawmap(g);
    }

     public int newtestmap()
    {
        //生成例题中图
        int k = 12;
        map1 = new int[k][k];
        for (int i = 0; i < k; i++)
                for (int j = 0; j < k; j++)
                    map1[i][j] = 0;
            for (int i = 0; i < k; i++)
                for (int j = 0; j < k; j++)
                {
                    
                    if (-1 < i && i < 3 && j==i+1)
                    {
                        map1[i][j] = 1;
                        map1[j][i] = 1;
                    }
                    if (3 < i && i < 7 &&j==i+1)
                    {
                        map1[i][j] = 1;
                        map1[j][i] = 1;
                    }
                    if (7 < i && i < 11 &&j==i+1)
                    {
                        map1[i][j] = 1;
                        map1[j][i] = 1;
                    }
                    int temp = i - j;
                    if (temp < 0) temp *= -1;
                    if (temp == 4)
                    {
                        map1[i][j] = 1;
                        map1[j][i] = 1;
                    }
                }
        initmap(map1, k);
        return k;
    }
     
    public void initmap(int [][]map,int num1)
    {//初始化图
        int rx0, ry0;
        double r0 = jPanel2.getHeight()/2-15;
        rx0 = (int) ((jPanel2.getWidth() - jPanel2.getX()) / 2) ;
        ry0 = (int) ((jPanel2.getHeight() - jPanel2.getY())/ 2 );
        //this.jTextArea1.append("半径："+r0+"圆心：X="+rx0+";Y="+ry0+"\n");
        //this.jTextArea1.append("画布参数：："+canvas1.getWidth()+canvas1.getHeight()+"\n");
        point = new int[2][num1];
        pointColor = new Color[num1];
        double a = (double)360 / (double)(num1);
        for(int j=0;j<num1;j++)
        {
            double b=((double)j) * a;
            point[0][j] = (int)(rx0 - (Math.cos(b) * r0));
            point[1][j] = (int)(ry0 - (Math.sin(b) * r0));
            pointColor[j] = Color.RED;
        }
    } 
     
    public void drawmap(Graphics2D g)
    {//最主要的画图函数
        int num1 = num;
        int len1 = 0;
        //this.jTextArea1.setText("");
        g.setColor(Color.WHITE);
        g.fillRect(jPanel2.getX()-20, jPanel2.getY()-40, jPanel2.getWidth()+50, jPanel2.getHeight()+50);
        BasicStroke bs=new BasicStroke(4.0f);
        /*
        g.setColor(Color.RED);
        g.setStroke(bs);
        for (int i = 0; i < num1; i++)
        {
           g.drawOval(point[0][i]-2, point[1][i]-2, 4, 4);
           
        }
         * * */
        if(theSign==0)
            g.setColor(Color.BLACK);
        if(theSign==1)
            g.setColor(Color.BLUE);
        bs=new BasicStroke(1.0f);
        g.setStroke(bs);
         
        //g.setPaint(new Color(50,70,120));
            if (point != null)
            {

                for (int i = 0; i < num1; i++)
                {
                    for (int j = i+1; j < num1; j++)
                    {
                        if (map1[i][j] == 1 || map1[j][i] == 1)
                        {
                            g.drawLine(point[0][i], point[1][i], point[0][j], point[1][j]);
                            len1++;
                        }
                    }
                }
                for (int i = 0; i < num1; i++)
                {
                    drawPoint(g,pointColor[i],point[0][i],point[1][i],i);
                }
                len = len1;
                //this.jTextArea1.append("拓扑图已经画好了！\n");
                //this.jTextArea1.append("点数为："+num1 + "边数为：" + len+"\n");
            }
            //else this.jTextArea1.append("拓扑图还未画！");
        if(choiceP!=null||choiceE!=null)
        {
            if(choiceE!=null){
            g.setColor(Color.BLUE);
            BasicStroke bs5=new BasicStroke(2.0f);
            g.setStroke(bs5);
            for(int i=0;i<choiceE[0].length;i++)
            {
                if(map1[choiceE[0][i]][choiceE[1][i]]==1||map1[choiceE[1][i]][choiceE[0][i]]==1)
            g.drawLine(point[0][choiceE[0][i]], point[1][choiceE[0][i]], point[0][choiceE[1][i]], point[1][choiceE[1][i]]);
            }
            }
            if(choiceP!=null){
            for(int i=0;i<choiceP.length;i++)
            {
                int get = choiceP[i];
            g.setColor(Color.BLUE);
            BasicStroke bs6=new BasicStroke(2.0f);
            g.setStroke(bs6);
            g.drawOval(point[0][get]-4,point[1][get]-4, 8,8);
            g.drawLine(point[0][get]-7, point[1][get], point[0][get]-4, point[1][get]);
            g.drawLine(point[0][get]+4, point[1][get], point[0][get]+7, point[1][get]);
            g.drawLine(point[0][get], point[1][get]-7, point[0][get], point[1][get]-4);
            g.drawLine(point[0][get], point[1][get]+4, point[0][get], point[1][get]+7);
            }
            }
        }
    }
    
    public void drawPoint(Graphics2D g,Color color,int x,int y,int i)
    {

        if(theSign==0){
            /*
            Random random1 = new Random();
            int a = 198 + random1.nextInt(198);
            int b = 198 + random1.nextInt(198);
            int c = 198 + random1.nextInt(198);
            Color randomColor = Color.getHSBColor(a, b, c);
             * */
            if(!Import){
                g.setColor(color);
                g.fillOval(x-4, y-4, 9, 9);
                g.setColor(Color.BLACK);
                BasicStroke bs=new BasicStroke(4.0f);
                bs=new BasicStroke(1.0f);
                g.setStroke(bs);
                g.drawOval(x-4, y-4, 8, 8);
                if(i!=-1)
                g.drawString(String.valueOf(i+1), x+4, y-4);
                //g.setColor(Color.BLACK);
            }
            else
            {
                g.setColor(color);
                g.fillOval(x-4, y-4, 9, 9);
                g.setColor(Color.BLACK);
                BasicStroke bs=new BasicStroke(4.0f);
                bs=new BasicStroke(1.0f);
                g.setStroke(bs);
                g.drawOval(x-4, y-4, 8, 8);
                g.setColor(Color.BLUE);
                if(i!=-1)
                g.drawString(String.valueOf(ImportNum[i]), x+4, y-4);
                //g.setColor(Color.BLACK);
            }
        }
        if(theSign == 1)
        {

            g.setColor(color);
            g.fillOval(x-3, y-3, 7, 7);
            g.setColor(Color.BLACK);
            BasicStroke bs=new BasicStroke(4.0f);
            bs=new BasicStroke(1.0f);
            g.setStroke(bs);
            g.drawOval(x-3, y-3, 6, 6);
            //g.setColor(Color.BLUE);
            //if(i!=-1)
            //g.drawString(String.valueOf(i+1), x+4, y-4);
        }
    }

    @Action
    public void open_File() {
        //打开Pajak的NET文件
        try{
        int open = fileChooser.showOpenDialog(this.fileBox);
        if(open ==fileChooser.APPROVE_OPTION)
        {
            NewAll();
            File openFileName = fileChooser.getSelectedFile();
            String fileName = new String(openFileName.getPath());
            BufferedReader inStream =new BufferedReader(new FileReader(fileName));
            try{
            //String some = inStream.readUTF();
                StreamTokenizer st = new StreamTokenizer(inStream);
                st.nextToken();
                //this.jTextArea2.append(String.valueOf(st.nval));
                st.nextToken();
                //this.jTextArea2.append(String.valueOf(st.sval));
                String s = new String(st.sval);
                if(s.equals("Vertices"))
                {
                    st.nextToken();
                    num = (int)st.nval;
                }

                st.nextToken();
            //this.jTextField1.setText(some);
            //this.jTextArea2.append(String.valueOf(num));
            map1=new int[num][num];
            point=new int[2][num];
            pointColor = new Color[num];
            for(int i=0;i<num;i++){
                //String s1 = st.sval;
                if(st.nval==0.0)
                    break;
                
                st.nextToken();
                if(st.sval!=null&&st.sval.equals("Edges"))
                    break;
                st.nextToken();
                if(st.sval!=null&&st.sval.equals("Edges"))
                    break;
                point[0][i] = (int)((double)(this.jPanel2.getWidth())*st.nval);
                st.nextToken();
                point[1][i] = (int)((double)(this.jPanel2.getHeight())*st.nval);
                //this.jTextArea2.append(this.canvas1.getWidth()+" "+this.canvas1.getHeight());
                //this.jTextArea2.append(point[0][i]+" "+point[1][i]);
                st.nextToken();
                st.nextToken();
                //this.jTextArea2.append(String.valueOf(st.nval)+" ");
                //this.jTextArea2.append("\n");
            }
            //st.nextToken();
            if(st.sval!=null&&st.sval.equals("Edges"))
            {
                 st.nextToken();
                while(!(st.ttype == st.TT_EOF))
                {
                    int a,b;
                    a = (int)st.nval-1;
                    st.nextToken();
                    b = (int)st.nval-1;
                    st.nextToken();
                    st.nextToken();
                    map1[a][b] = map1[b][a] = 1;
                }
            }
            else {
                st.nextToken();
                if(st.sval!=null&&st.sval.equals("Edges"))
                {
                     st.nextToken();
                    while(!(st.ttype == st.TT_EOF))
                    {
                        int a,b;
                        a = (int)st.nval-1;
                        st.nextToken();
                        b = (int)st.nval-1;
                        st.nextToken();
                        st.nextToken();
                        map1[a][b] = map1[b][a] = 1;
                    }
                }
            }
            for(int i=0;i<num;i++){
                pointColor[i] = Color.RED;
            }
            theSign = 1;
            }catch(IOException e){
                //this.jTextArea2.append(e.getMessage());
            }
            finally {inStream.close();}

        }
        }
        catch(Exception ex)
        {
            //this.jTextField1.setText(ex.getMessage());
            ex.printStackTrace();
        }
        finally{
            drawAgain();
        }
    }
    
    public void NewAll() {
        //新建
        num = 0;
        map1 = null;
        point = null;
        //jTextArea1.setText("");
        //jTextArea2.setText("");
        //jTextField1.setText("");
        jPanel2.repaint();
        
    }
    
    public void drawAgain()
    {//全部重画
        Graphics2D g=(Graphics2D)jPanel2.getGraphics();
        drawmap(g);
        
    }

    

  
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
    private JDialog fileBox;
}
